import { getAreaObj, regularRule, uploadType } from '@/utils/util'
import { toSearchHandle, configToSearch, configToReserveSearch } from '@/views/datacenter/comprehensiveQueries/components/NewKeywords/components/utils/index'

export const detailConfig = {
	inline: false,
	showBtn: false,
	labelPosition: 'left',
	column: [
		{ label: '单位所属区域', prop: 'areasName', span: 8 },
		{ label: '单位统一社会信用代码', prop: 'creditCode', span: 8 },
		{
			label: '证件类型',
			prop: 'identifyType',
			propName: 'identifyTypeLabel',
			type: 'remoteSelect',
			code: 'ID_CARD_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{ label: '出生日期', prop: 'birthday', span: 8 },
		{ label: '证件号码', prop: 'idCard', span: 8 },
		{ label: '联系方式', prop: 'phone', span: 8 },
		{ label: '通讯地址', prop: 'address', span: 8 },
		{
			label: '专家职称',
			prop: 'jobTitle',
			propName: 'jobTitleLabel',
			type: 'remoteSelect',
			code: 'JOB_TITLE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '专家职务',
			prop: 'jobPosition',
			maxlength: '20',
			showWordLimit: true,
			type: 'text',
			span: 8,
		},
		{
			label: '电子邮件',
			prop: 'email',
			span: 8,
		},

		{
			label: '民族',
			prop: 'nationality',
			propName: 'nationalityLabel',
			type: 'remoteSelect',
			code: 'NATIONALITY',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '毕业院校',
			prop: 'graduateInstitutions',
			type: 'input',
			span: 8,
		},
		{
			label: '所学专业',
			prop: 'major',
			type: 'input',
			span: 8,
		},
		{
			label: '毕业时间',
			prop: 'graduationDate',
			changeField: false,
			type: 'month',
			format: 'YYYY年MM月',
			valueFormat: 'YYYYMM',
			span: 8,
		},
		{
			label: '学  历',
			prop: 'education',
			propName: 'educationLabel',
			type: 'remoteSelect',
			code: 'EDUCATION',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '学  位',
			prop: 'degree',
			propName: 'degreeLabel',
			type: 'remoteSelect',
			code: 'DEGREE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '单位性质',
			prop: 'natureOfUnit',
			type: 'input',
			span: 8,
		},
		{
			label: '是否为两院院士',
			prop: 'isAcademician',
			propName: 'isAcademicianLabel',
			type: 'select',
			multiple: true,
			dicData: [
				{ label: '否', value: '1' },
				{ label: '科学院院士', value: '2' },
				{ label: '工程院院士', value: '3' },
			],
			span: 8,
		},
		{
			label: '担任时间',
			prop: 'servingTime',
			changeField: false,
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '研究方向',
			prop: 'researchDirection',
			propName: 'researchDirectionLabel',
			type: 'remoteSelect',
			code: 'RESEARCH_DIRECTION',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: true,
			span: 8,
		},
		{
			label: '其他研究方向',
			prop: 'otherResearchDirections',
			type: 'input',
			span: 8,
		},
		{
			label: '专家介绍',
			prop: 'introduce',
			span: 8,
		},
		{
			label: '相关证书',
			prop: 'otherCertify',
			custome: 'file',
			span: 8,
		},
		{
			label: '能力业绩证明材料',
			prop: 'otherCertifyFiles',
			span: 8,
		},
	],
	customeHeader: {
		type: 'CardTwo',
		title: 'professorName',
		avatar: 'professorImg',
		tipList: [
			{ prop: 'phone', type: 'tip-success', label: '联系电话' },
			{ prop: 'enterpriseName', type: 'tip-success', label: '单位名称' },
		],
		tagList: [
			{ prop: 'professorLevelLabel', custome: 'tag', type: 'success', label: '推荐单位' },
			{ prop: 'jobTitleLabel', custome: 'tag', type: 'success', label: '专家职称' },
		],
		// menuBtn: [
		// 	{
		// 		icon: 'delete',
		// 		label: '删除专家',
		// 		type: 'danger',
		// 		operate: 'delete',
		// 		auth: 'view_dpProfessor_del',
		// 		text: false,
		// 		show: true,
		// 		plain: true,
		// 	},
		// ],
	},
}
// 基础
export const BaseFormConfig = {
	inline: false,
	showBtn: false,
	labelPosition: 'top',
	column: [
		{
			uploadTip: '专家照片',
			prop: 'professorImg',
			type: 'upload',
			showFileList: false,
			limit: 1,
			multiple: false,
			span: 24,
		},
		{
			label: '专家姓名',
			prop: 'professorName',
			maxlength: '20',
			showWordLimit: true,
			type: 'text',
			rules: [{ required: true, message: '请输入专家姓名' }],
			span: 8,
		},
		{
			label: '单位所属区域',
			prop: 'areas',
			propName: 'areasName',
			type: 'AplidAreaSelect',
			rules: [{ required: true, message: '请选择单位所属区域' }],
			span: 16,
		},
		{
			label: '证件类型',
			prop: 'identifyType',
			propName: 'identifyTypeLabel',
			type: 'remoteSelect',
			code: 'ID_CARD_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
			rules: [{ required: true, message: '请选择证件类型' }],
		},
		{
			label: '证件号码',
			prop: 'idCard',
			type: 'input',
			editDisabled: true,
			span: 8,
			rules: [
				{ pattern: regularRule.idCard, message: '请输入正确的证件号码' },
				{ required: true, message: '请输入证件号码' },
			],
		},
		{
			label: '联系电话',
			prop: 'phone',
			maxlength: '11',
			showWordLimit: true,
			type: 'text',
			rules: [{ pattern: regularRule.phone, message: '请输入正确的联系电话' }],
			span: 8,
		},
		{
			label: '单位名称',
			prop: 'enterpriseName',
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
			span: 8,
		},
		{
			label: '单位统一社会信用代码',
			prop: 'creditCode',
			maxlength: '18',
			showWordLimit: true,
			type: 'text',
			rules: [
				{
					pattern: regularRule.code,
					message: '请输入正确的单位统一社会信用代码',
				},
			],
			span: 8,
		},
		{
			label: '专家职称',
			prop: 'jobTitle',
			propName: 'jobTitleLabel',
			type: 'remoteSelect',
			code: 'JOB_TITLE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '专家职务',
			prop: 'jobPosition',
			maxlength: '20',
			showWordLimit: true,
			type: 'text',
			span: 8,
		},
		{
			label: '电子邮件',
			prop: 'email',
			type: 'input',
			span: 8,
		},
		{
			label: '民族',
			prop: 'nationality',
			propName: 'nationalityLabel',
			type: 'remoteSelect',
			code: 'NATIONALITY',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '毕业院校',
			prop: 'graduateInstitutions',
			type: 'input',
			span: 8,
		},
		{
			label: '所学专业',
			prop: 'major',
			type: 'input',
			span: 8,
		},
		// {
		// 	label: '毕业时间',
		// 	prop: 'graduationDate',
		// 	type: 'month',
		// 	format: 'YYYY年MM月DD日',
		// 	valueFormat: 'YYYY-MM-DD',
		// 	span: 8,
		// },
		{
			label: '学  历',
			prop: 'education',
			propName: 'educationLabel',
			type: 'remoteSelect',
			code: 'EDUCATION',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '学  位',
			prop: 'degree',
			propName: 'degreeLabel',
			type: 'remoteSelect',
			code: 'DEGREE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '单位性质',
			prop: 'natureOfUnit',
			type: 'input',
			span: 8,
		},
		{
			label: '是否为两院院士',
			prop: 'isAcademician',
			propName: 'isAcademicianLabel',
			type: 'select',
			multiple: true,
			dicData: [
				{ label: '否', value: '1' },
				{ label: '科学院院士', value: '2' },
				{ label: '工程院院士', value: '3' },
			],
			span: 8,
		},
		{
			label: '担任时间',
			prop: 'servingTime',
			changeField: false,
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
		{
			label: '研究方向',
			prop: 'researchDirection',
			propName: 'researchDirectionLabel',
			type: 'remoteSelect',
			code: 'RESEARCH_DIRECTION',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: true,
			span: 8,
		},
		{
			label: '其他研究方向',
			prop: 'otherResearchDirections',
			type: 'input',
			span: 8,
		},
		{
			label: '推荐单位',
			prop: 'recommendedUnit',
			propName: 'professorLevelLabel',
			type: 'remoteSelect',
			code: 'PROFESSOR_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},

		{
			label: '通讯地址',
			prop: 'address',
			maxlength: '140',
			showWordLimit: true,
			type: 'textarea',
			autosize: {
				minRows: 1,
			},
			span: 24,
		},
		{
			label: '专家介绍',
			prop: 'introduce',
			maxlength: '500',
			showWordLimit: true,
			type: 'textarea',
			autosize: {
				minRows: 1,
			},
			rows: 1,
			span: 24,
		},
		// ++++++++++++++++++++++ 证书信息++++++++++++++++++++++
		{
			label: '相关证书',
			prop: 'otherCertify',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'text',
			labelPosition: 'top',
			showFileList: true,
			limit: 9,
			multiple: true,
			changeField: true,
			span: 24,
		},
		{
			label: '能力业绩证明材料',
			prop: 'otherCertifyFiles',
			maxlength: '500',
			showWordLimit: true,
			type: 'textarea',
			autosize: {
				minRows: 1,
			},
			span: 24,
		},
	],
}

const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '单位地区', prop: 'tableAreaName', width: 200 },
		{ label: '单位名称', prop: 'enterpriseName' },
		{ label: '身份证号', prop: 'idCard', plusXing: '2,2' },
		{ label: '姓名', prop: 'professorName' },
		{ label: '联系方式', prop: 'phone', plusXing: '5,2' },
		{
			label: '职称',
			prop: 'jobTitleLabel',
		},
		{
			label: '推荐单位',
			prop: 'professorLevelLabel',
		},
		{ label: '入库时间', prop: 'createTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 200,
			fixed: 'right',
		},
	],
}
export const api = {
	moreSearch: 'view_dpProfessor_search',
	reserveSearch: 'view_dpProfessor_search',
	index: 'view_dpProfessor_page',
	add: 'view_dpProfessor_gather',
	edit: 'view_dpProfessor_edit',
	detail: 'view_dpProfessor_view',
	delete: 'view_dpProfessor_del',
	import: 'view_dpProfessor_import',
	export: 'view_dpProfessor_export',
}
// 专家抽选
export const SelectLotForm = {
	inline: false,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '数量',
			prop: 'randomNum',
			type: 'number',
			min: 1,
			controls: false,
			span: 12,
		},
		{
			label: '推荐单位',
			prop: 'professorLevel',
			type: 'remoteSelect',
			code: 'PROFESSOR_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 12,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '证件号码',
			prop: 'idCard',
			type: 'input',
			span: 6,
		},
		{
			label: '单位所属区域',
			prop: 'areas',
			propName: 'areasName',
			type: 'AplidAreaSelect',
			span: 12,
		},
		{
			label: '姓名',
			prop: 'professorName',
			type: 'input',
			span: 6,
		},
		{
			label: '联系方式',
			prop: 'phone',
			type: 'input',
			span: 6,
		},
		{
			label: '单位名称',
			prop: 'enterpriseName',
			type: 'input',
			span: 6,
		},
		{
			label: '职称',
			prop: 'jobTitle',
			type: 'remoteSelect',
			code: 'JOB_TITLE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 6,
		},
		{
			label: '推荐单位',
			prop: 'professorLevel',
			type: 'remoteSelect',
			code: 'PROFESSOR_LEVEL',
			api: 'getDictItemList',
			dataType: 'number',
			filterKey: 'value',
			multiple: false,
			span: 6,
		},
	],
}
// 全字段搜索
const moreSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [...configToSearch(BaseFormConfig.column)],
}
const reserveSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [...configToReserveSearch(BaseFormConfig.column)],
}
export const baseConfig = {
	pageName: '养老专家',
	rowKey: 'id',
	addLabel: '采集数据',
	needPigeonhole: true, // 是否显示顶部关于归档的部分
	tipLabel: 'professorName',
	dictcodes: [
		'RESEARCH_DIRECTION',
		'COMMON_FLAG',
		'ID_CARD_TYPE',
		'JOB_TITLE',
		'PROFESSOR_LEVEL',
		'COMMON_FLAG',
		'EDUCATION',
		'DEGREE',
		'NATIONALITY',
	],
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		index: 'view_dpProfessor_page',
		add: 'view_dpProfessor_gather',
		edit: 'view_dpProfessor_edit',
		delete: 'view_dpProfessor_del',
		import: 'view_dpProfessor_import',
		export: 'view_dpProfessor_export',
		detail: 'view_dpProfessor_view',
		mulitSet: 'mulitSet',
	},
	paramsObj: {
		code: 3012,
	},
	menuAction: [
		{
			icon: 'editor',
			label: '专家抽选',
			type: 'default',
			operate: 'SelectLot',
			auth: '',
			text: false,
			show: true,
		},
	],
	menuBtn: [
		{
			icon: 'editor',
			label: '查看档案',
			type: 'primary',
			operate: 'Archives',
			auth: 'view_dpProfessor_view',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '65%', // fullscreen: true
	},
	// 全字段搜索
	moreSearchConfig,
	reserveSearchConfig,
	searchConfig,
	detailConfig,
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const area: any = getAreaObj(item, '', 'set')
			const tempObj = {
				...item,
				areas: area.areaIds,
				areasName: area.names,
				tableAreaName: [item.areaName, item.streetName, item.communityName].filter(Boolean).join(''),
			}
			return tempObj
		})
		return Promise.resolve(Object.freeze(tableData))
	},
	beforeOnLoadFormate: (query) => {
		query = toSearchHandle(moreSearchConfig, reserveSearchConfig, query)
		return new Promise((resolve, reject) => {
			let arIds: any = getAreaObj(query.areas, '')
			resolve({
				...query,
				...arIds,
				areas: undefined,
			})
		})
	},
	formConfig: {
		...BaseFormConfig,
		showBtn: true,
	},
	tableConfig,
}
